package com.dubbo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.entity.Admin;
import com.dubbo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 客户端测试
 *
 * @author zhang he qiang
 */
@Controller
@RequestMapping("/dubbo/admin")
public class AdminController {

    /****************************************************** Query *****************************************************/

    @Reference(interfaceName = "com.dubbo.service.AdminService", version = "1.0.0", check = false)
    private AdminService service;

    /**
     * 查询-根据主建id
     * @Author zhang heqiang
     * @Date 2020/7/20
     * @param id
     * @param model
     * @return java.lang.String
     **/
    @RequestMapping(value = "/findOne/{id}")
    public String findOne(@PathVariable("id") Long id, Model model) {
        Admin admin = service.selectByPrimaryKey(id);
        model.addAttribute("admin", admin);
        return "hello";
    }

    /**
     * 查询-全部数据
     * @Author zhang heqiang
     * @Date 2020/7/20
     * @param model
     * @return java.lang.String
     **/
    @RequestMapping(value = "/findAll")
    public String findAll(Model model) {
        List<Admin> list = service.selectAll();
        model.addAttribute("list", list);
        return "admin/list";
    }
}
